﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Honestysoft.BaseObject;
using System.Data;
using Honestysoft.Financing.Model;
using System.Text;

namespace Honestysoft.Financing.WebUI.Module.Reports.JSON
{
    /// <summary>
    /// GetProject 的摘要说明
    /// </summary>
    public class GetProject : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            QueryParameters query = new QueryParameters();
            OrderParameters order = new OrderParameters();
            order.Add("SortCode");
            DataTable dt = new Honestysoft.BaseObject.BaseBusinessLogic<BD_Project>().GetTable(query, order);
            string responseData = "";
            if (dt != null && dt.Rows.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("[");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append("{");
                    sb.Append("\"id\":");
                    sb.AppendFormat("\"{0}\",", dr["SN"].ToString());
                    sb.Append("\"text\":");
                    sb.AppendFormat("\"{0}\"", dr["SN"].ToString() + " " + dr["Name"].ToString());
                    sb.Append("},");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]");
                responseData = sb.ToString();
            }
            context.Response.Write(responseData);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}